﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using VK.Casemeet.Groups;
using VK.Comm;
using VK.Casemeet.Merchants;

namespace VK.Casemeet.Web.Front
{
    public partial class GroupDetail : System.Web.UI.Page
    {
        public string ImgPath = "";//图片路径;
        public DateTime EndingTime =DateTime.MinValue ;//团购剩余时间;
        public string groupid ="0";//记录当前团购ID,在页面中使用.
        public bool isLogin = false;
        protected void Page_Load(object sender, EventArgs e)
        {
            
            int gcid = Util.GetRouteDataInt("gcid");
            groupid = gcid.ToString();//团购ID
            BindCategoryies();//分类
            initilizGroup(gcid);//团购详细信息
            isLogin = Members.MemberBLL.IsSessionMember();

           
        }

        //分类列表
        private void BindCategoryies()
        {
            repGroups.DataSource = GroupsBLL.GetCategories(0, "");
            repGroups.DataBind();
        }


        /// <summary>
        /// 1.取出当前团购信息
        /// 2.赋值到当前页面
        /// </summary>
        /// <param name="gcid"></param>
        private void initilizGroup(int gcid)
        {
            GroupsEntity group = GroupsBLL.GetGroups(gcid);//取出当前团购信息。
            if (group == null)
                return;

            ShopCard1.shop = ShopBLL.GetShop(group.ShopID);//取出企业信息

            tbtitle.Text = group.Title;//标题
            tbdisprice.Text = group.Discount.ToString();//折扣价
            tbprice.Text = group.Price.ToString();//市场价
            tbdiscount.Text = DisCount(tbprice.Text,tbdisprice.Text);//折扣
            tbsaveprice.Text = ((float)group.Price - group.Discount).ToString();//节省的票票
            tbContent.Text = group.Content;//内容。
            ImgPath = group.Foucsmap;
            EndingTime = group.EndingTime;
            tbgroupcount.Text = group.SigupTotal.ToString();

        }


        private string DisCount(string origprice, string disprice)
        {
            Single orignum = 0; Single disnum = 0;
            Single.TryParse(origprice, out orignum);
            Single.TryParse(disprice, out disnum);
            if (disnum == 0)
                return "";

            return Math.Round((disnum / orignum*10), 1).ToString();
        }


        
    }
}